package com.xiaohao.ctdemo;

import com.mathworks.toolbox.javabuilder.MWException;
import drug.Drug;
import org.junit.Test;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @author 小浩
 * @date 2018-07-22 18:53
 * @package com.xiaohao.ctdemo
 * @description
 */
public class Rename {
    @Test
    public void rename() {
//        File file=new File("./src/main/resources/static/ctimages/");
//        for (File file1:file.listFiles()){
//            String name=file1.getName();
//            if (name.startsWith("00")){
//                file1.renameTo(new File(file,name.replaceFirst("00","")));
//            }else if (name.startsWith("0")){
//
//                file1.renameTo(new File(file,name.replaceFirst("0","")));
//
//            }
//            System.out.println(name.replaceFirst("0",""));
//        }
    }


    @Test

    public void demo() throws IOException {
        ProcessBuilder processBuilder = new ProcessBuilder("cmd.exe", "/c", "dir");
//        Process process=processBuilder.start();

        processBuilder.redirectOutput(ProcessBuilder.Redirect.INHERIT);
        processBuilder.start();
    }


    @Test
    public void demo02() throws IOException, MWException {
        int num = 1;
        System.out.println(num);
        Drug drug = null;
        List<String> list = new LinkedList<>();
        BufferedReader br = new BufferedReader(new FileReader(("./nameData.txt")));
        int mmm = num;
        for (int i = 1; i <= mmm; i++) {
            if (mmm == i) {
                list.add(br.readLine());
                System.out.println(list);
            } else {
                br.readLine();
            }
        }
        drug = new Drug();
        Object[] result = drug.main(2, num);
        list.add(String.valueOf(result[0]));
        String numStr = String.valueOf(result[1]);
        String[] replace = numStr.split("    ");
        for (String str : replace) {
            System.out.println(str);
        }
        for (String number : replace) {
            BufferedReader bufferedReader = new BufferedReader(new FileReader(("./nameData.txt")));
            int numm = Integer.parseInt(number.replace(" ", ""));
            for (int i = 1; i <= numm; i++) {

                if (numm == i) {
                    list.add(bufferedReader.readLine());
                } else {
                    bufferedReader.readLine();
                }
            }

        }
        System.out.println(list);

    }

    @Test
    public void test04() {

    }


}
